import { create } from 'zustand'
import { persist, devtools  } from "zustand/middleware"
// and modify our existing state

let store = (set: any) => ({
    usedMenu: [], //用到的菜单
    userInfo: {},
    userMenus: [],
    currentMenuCode: [],
    login: {
        postId: "",
        token: ""
    },
    loginUserRole: {
        systemAdmin: false,
        orgId: ''
    },
    setUsedMenu: (usedMenu: any[]) => {
        set(() => ({ usedMenu: usedMenu }))
    },
    setUserInfo: (userInfo: any) => {
        set(() => ({ userInfo: userInfo }))
    },
    setUserMenus: (userMenus: any[]) => {
        set(() => ({ userMenus: userMenus }))
    },
    setCurrentMenuCode: (currentMenuCode: string[]) => {
        set(() => ({ currentMenuCode: currentMenuCode }))
    },
    setLogin: (login: any) => {
        set(() => ({ login: login }))
    },
    setLoginUserRole: (role: any) => {
        set(() => ({ loginUserRole: role }))
    }
});
const env = import.meta.env.VITE_APP_ENV
store = persist(store, { name: "baseInfo" })
if (env === 'dev') {
    // 开启浏览器调试
    store = devtools(store)
}
const useStore = create(store);
export default useStore;
